<template>
  <ul class="todo-list">
    <!-- completed: 完成的类名 -->
    <!-- 1.父传子获取数据,循环铺设到页面上 -->
    <li
      :class="{completed:obj.isDone}"
      v-for="(obj,index) in arr"
      :key="obj.id"
    >
      <div class="view">
        <input
          class="toggle"
          type="checkbox"
          v-model="obj.isDone"
        />
        <label>{{obj.name}}</label>
        <!-- 3. 删除任务 -->
        <!-- 3.1 绑定点击事件, -->
        <button
          class="destroy"
          @click="del(index)"
        ></button>
      </div>
    </li>
    <div
      class="box"
      v-if="this.arr.length == 0"
    > 没有任务了,快安排任务吧</div>
  </ul>

</template>

<script>
export default {
  props: ['arr'],
  methods: {
    del (ind) {
      // 3.3 子传父把要删除的数据的索引告诉父亲,
      this.$emit('delList', ind)
      console.log(ind);
    }
  }
}
</script>
<style scoped>
.box {
  height: 58px;
  text-align: center;
  line-height: 58px;
  font-size: 24px;
}
</style>